const app = getApp()
import {indexSearch} from '../../utils/api'
Component({
    properties: {
        list:{
            type: Array,
            value: []
        }
    },
    data: {
        navBarHeight: app.globalData.navBarHeight,
        menuRight: app.globalData.menuRight,
        menuBotton: app.globalData.menuBotton,
        menuHeight: app.globalData.menuHeight,
        canRun: true,
        timer: null,
    },
    methods: {
        debounce(callback, wait) {
            const { canRun, timer } = this.data;
            if (canRun) {
              callback();
              this.data.canRun = false;
            }
            timer && clearTimeout(this.data.timer);
            this.data.timer = setTimeout(() => {
              this.data.canRun = true;
            }, wait);
          },
        fun(event){
            let that = this;
            indexSearch(event).then(res=>{
               let value = res.data
               that.triggerEvent('myevent',{value})
            })
        },
        textLength(e){
            let length = e.detail.value.length
            this.triggerEvent('length',{length})

        },
        onSearch(event) {
            let value = event.detail.value
            this.fun.bind(this,value)()
            // this.debounce(this.fun.bind(this,value),500)
        }
    }
})